import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;


public class Clicker {
    /**
     * 模拟鼠标点击器,快速点击
     * @param args 点击次数,点击的间隔时间
     * @throws AWTException 可遇到的异常抛出
     */
    public static void main(String[] args) throws AWTException {
        JTextField maxClicksField = new JTextField(10);
        JTextField delayField = new JTextField(10);

        JPanel myPanel = new JPanel();
        myPanel.add(new JLabel("最大点击次数:"));
        myPanel.add(maxClicksField);
        myPanel.add(Box.createHorizontalStrut(15)); // 添加一些间距
        myPanel.add(new JLabel("点击间隔时间(ms):"));
        myPanel.add(delayField);

        int result = JOptionPane.showConfirmDialog(null, myPanel, "点击设置",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

        if (result == JOptionPane.OK_OPTION) {
            int maxClickCount = Integer.parseInt(maxClicksField.getText());
            int delay = Integer.parseInt(delayField.getText());

            int currentClickCount = 0;
            Robot robot = new Robot();

            while (currentClickCount < maxClickCount) {
                // 点击操作
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.delay(delay);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);

                currentClickCount++;
                System.out.println("当前点击次数: " + currentClickCount);
            }
        }
    }
}